﻿namespace Codeplex.Unity.AutoRegister.Config
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// Provide RegistTypeTrait class.
    /// </summary>
    public abstract class RegistTypeTraitProvider
    {
        /// <summary>
        /// Get target types.
        /// </summary>
        /// <returns></returns>
        protected abstract IEnumerable<Type> GetTypes();

        /// <summary>
        /// Create RegistTypeTrait from Type.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        protected abstract IEnumerable<RegistTypeTrait> BuildTrait(Type type);

        /// <summary>
        /// Get all RegistTypeTrait.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<RegistTypeTrait> GetRegistTypeTraits()
        {
            foreach (var type in this.GetTypes())
            {
                foreach (var trait in this.BuildTrait(type))
                {
                    yield return trait;
                }
            }
        }
    }
}
